/**
 * @project lauwsys
 * @author Christian Teguh
 * @created 23 Okt 2011 03.04.59
 *
 */
package com.chimoz.lauwsys.mvc.master;

import java.util.HashMap;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.chimoz.lauwsys.business.BrandManager;
import com.chimoz.lauwsys.domain.Brand;

@Controller
@RequestMapping( "/brand/*" )
public class BrandController {

	private BrandManager brandManager;
	
	@Inject
	private BrandController(BrandManager brandManager) {
		this.brandManager = brandManager;
	}
	
	@RequestMapping( value = "/byid/{id}", method= {RequestMethod.POST, RequestMethod.GET } )
	public ModelAndView byId(@PathVariable String id){
		Brand brand = this.brandManager.getBrandById(new Long(id));
		ModelAndView mav = new ModelAndView();
		mav.setViewName("chinfo");
		mav.addObject("information", brand);
		return mav;
	}
	
	
	@RequestMapping( "/list" )
	public ModelAndView listBrand(@RequestParam("limit") String limit, @RequestParam("offset") String offset) {
		Map<String, String> criteria = new HashMap<String, String>();
		criteria.put("limit", limit);
		criteria.put("offset", offset);
		
		ModelAndView mav = new ModelAndView();
		mav.setViewName("chinfo");
		mav.addObject("information", criteria);
		return mav;
	}
}
